#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <U8g2lib.h>
#include <stdio.h>

#include "drv_common.h"
#include <drv_soft_i2c.h>

#define OLED_I2C_PIN_SCL                  GET_PIN(H, 11) // 22  // PH11
#define OLED_I2C_PIN_SDA                  GET_PIN(H, 12) // 23  // PH12

static U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,\
                                         /* clock=*/ OLED_I2C_PIN_SCL,\
                                         /* data=*/ OLED_I2C_PIN_SDA,\
                                         /* reset=*/ U8X8_PIN_NONE);
void oled_display()
{
    u8g2.begin();
    u8g2.clearBuffer();
    while(1)
    {
        static int i;
        static char str;
        for (i = 0; i < 1001; i++) {
            sprintf((char*)str,"i=%d",i);
            u8g2.setFont(u8g2_font_10x20_tr);            // choose a suitable font
            u8g2.drawStr(30, 20, "TEST");   // write something to the internal memory
            u8g2.drawStr(30, 40, (char*)str);   // write something to the internal memory
            //u8g2.drawStr(30, 18, "Embeded FlyBrother");   // write something to the internal memory
            u8g2.sendBuffer();                          // transfer internal memory to the display
            rt_thread_mdelay(200);
            u8g2.clearBuffer();
            if (i==1000) {
                i=0;
            }
        }
    }
}
MSH_CMD_EXPORT(oled_display, oled start);

